<?php
$v_current_style_name = "round_row";
$v_export_type = 1;
if(isset($_REQUEST['rad_exporttype'])){
	$v_export_type = $_REQUEST['rad_exporttype'];
}
echo $v_export_type;
//Begin//Xay dung chuoi XML chua gia tri
$v_list_xml_tag = "";
if(isset($_REQUEST['hdn_list_xml_tag'])){
	$v_list_xml_tag = $_REQUEST['hdn_list_xml_tag'];
}
$v_list_xml_value = "";
if(isset($_REQUEST['hdn_list_xml_value'])){
	$v_list_xml_value = $_REQUEST['hdn_list_xml_value'];
}
$v_xml_str = '<?xml version="1.0" encoding="UTF-8"?><root><data_list>';
for ($i=0; $i<_list_get_len($v_list_xml_tag,_CONST_SUB_LIST_DELIMITOR); $i++){
	$v_xml_str = $v_xml_str ."<"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
	$v_xml_str = $v_xml_str .trim(_replace_XML_bad_char(_list_get_at($v_list_xml_value,$i,_CONST_SUB_LIST_DELIMITOR)));
	$v_xml_str = $v_xml_str ."</"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
}
$v_xml_str = $v_xml_str . "</data_list></root>";
//Doc file chua cau truc cua bao cao
$v_report_xml_file = "../xml/report/so_tiep_nhan_ho_so.xml";
$v_report_xml_string = _read_file($v_report_xml_file);
//lay du lieu
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'report_sql';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_sql_string = $table_struct_row["sql"];
$arr_all_record = Query_Data_For_Colunm_name($v_sql_string);
$v_count = sizeof($arr_all_record);
//lay cac thong tin tieu de cua form
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'table_struct_of_filter_form';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_form_title = $table_struct_row["form_title"];
$v_first_col_width = $table_struct_row["first_col_width"];
$v_second_col_width = (100-$v_first_col_width)."%";
//Begin//Bang chua cac thanh phan cua bao cao
$v_html_string = '';
//Lay cac thong tin ve tieu de cua bao cao
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'report_header';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_report_republic = $table_struct_row["report_republic"];
$v_parent_owner = $table_struct_row["parent_owner"];
$v_report_date = $table_struct_row["report_date"];
$v_large_title = $table_struct_row["large_title"];
$v_small_title = $table_struct_row["small_title"];
$v_html_string = $v_html_string  .'<table width="100%" cellpadding="0" cellspacing="0"><tr valign="top">';
$v_html_string = $v_html_string  .'<td align="center" class="normal_label">'.$v_parent_owner.'</td>';
$v_html_string = $v_html_string  .'<td align="center" class="normal_label">'.$v_report_republic.'</td>';
$v_html_string = $v_html_string  .'</tr><tr><td align="center" class="normal_label" colspan="5">*****************</td>';
$v_html_string = $v_html_string  .'</tr><tr><td style="text-align:right" class="normal_label" colspan="5">'.$v_report_date.'</td>';
$v_html_string = $v_html_string  .'</tr><tr><td style="text-align:center" class="normal_title" colspan="5">'.$v_large_title.'</td>';
$v_html_string = $v_html_string  .'</tr><tr><td style="text-align:center" class="small_title" colspan="5">'.$v_small_title.'</td>';
$v_html_string = $v_html_string  .'</tr></table>';
//Bang chua cac bin hidden
$v_html_string = $v_html_string . "<table width='100%' cellpadding='0' cellspacing='0'><tr><td>";
$v_html_string = $v_html_string . "<form action='index.php' method='post' name='f_dsp_single_reporttype'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_list_xml_tag' value=''>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_list_xml_value' value=''>";
$v_html_string = $v_html_string . "<input type='hidden' name='fuseaction' value='DISPLAY_SINGLE_REPORTTYPE'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_reporttype_filter' value='".$v_reporttype_filter ."'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_record_id' value=''>";
$v_html_string = $v_html_string . "</td></tr></table>";
//Doc cac dong cua form	
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'row';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
//Bang chua cac tieu thuc loc
$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr><td>";
while ($table_struct_rec) { 
	$table_struct_row = $table_struct_rec->getRow();
	$v_have_line_before = $table_struct_row["have_line_before"];
	$v_col_number = $table_struct_row["col_number"];
	$v_tag_list = $table_struct_row["tag_list"];
	$v_row_id = $table_struct_row["row_id"];
	$arr_tag = explode(",", $v_tag_list);
	if ($v_have_line_before=="true"){
		$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr>";
		$v_html_string = $v_html_string . "<td><hr width='100%' color='#66CCFF' size='1'></td>";
		$v_html_string = $v_html_string . "</tr></table>";
	}

	//Bang chua mot dong cua form
	$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'>";
	$v_html_table = "";
	$v_html_tag = "";									
	for($i=0;$i < sizeof($arr_tag);$i++){
		$formfield_rax = new RAX(); 
		$formfield_rec = new RAX(); 
		$formfield_rax->open($v_report_xml_string);
		$formfield_rax->record_delim = $arr_tag[$i];
		$formfield_rax->parse();
		$formfield_rec = $formfield_rax->readRecord(); 
		$formfield_row = $formfield_rec->getRow(); 
		$v_label = $formfield_row["label"];
		$v_type = $formfield_row["type"];
		$v_dataformat = $formfield_row["data_format"];
		$v_width = $formfield_row["width"];
		$v_row = $formfield_row["row"];
		$v_max = $formfield_row["max"];
		$v_min = $formfield_row["min"];
		$v_maxlength = $formfield_row["maxlength"];
		$v_note = $formfield_row["note"];
		$v_message = $formfield_row["message"];
		$v_optional = $formfield_row["optional"];
		$v_xml_tag_in_db = $formfield_row["xml_tag_in_db"];
		$v_js_function_list = $formfield_row["js_function_list"];
		$v_js_action_list = $formfield_row["js_action_list"];
		$v_readonly_in_edit_mode = $formfield_row["readonly_in_edit_mode"];
		$v_disabled_in_edit_mode = $formfield_row["disabled_in_edit_mode"];
		if ($v_xml_str!=""){
			$column_rax = new RAX(); 
			$column_rec = new RAX();
			$column_rax->open($v_xml_str);
			$column_rax->record_delim = 'data_list';
			$column_rax->parse();
			$column_rec = $column_rax->readRecord(); 
			$column_row = $column_rec->getRow();
			$v_value = _restore_XML_bad_char($column_row[$v_xml_tag_in_db]); 
		}
		if ($v_type=="selectbox"){
			$v_selectbox_option_sql = $formfield_row["selectbox_option_sql"];
			$v_selectbox_id_column = $formfield_row["selectbox_option_id_column"];
			$v_selectbox_name_column = $formfield_row["selectbox_option_name_column"];
		}
		if ($v_type=="checkboxmultiple"){
			$v_checkbox_multiple_sql = $formfield_row["checkbox_multiple_sql"];
			$v_checkbox_multiple_id_column = $formfield_row["checkbox_multiple_id_column"];
			$v_checkbox_multiple_name_column = $formfield_row["checkbox_multiple_name_column"];
		}
		$v_html_table = $v_html_table . "<col width='$v_first_col_width'>" . "<col width='$v_second_col_width'>";		
		$v_html_tag = $v_html_tag . Generate_HTML_Output();		
	}
	$v_html_string = $v_html_string .  $v_html_table . "<tr id = '$v_row_id' style='display:block'>" . "<td class='normal_label'>" . $v_html_tag."</td>";
	$v_html_string = $v_html_string . "</tr></table>";
	$table_struct_rec = $table_struct_rax->readRecord();
}
$v_html_string = $v_html_string . "</td></tr></table>";
//Het phan bang chua cac tieu thuc loc
//In danh sach cac ho so thoa man cac tieu thuc loc
$v_html_string = $v_html_string  . '<table class="list_table2" width="100%" cellpadding="0" cellspacing="0">';
$v_html_temp_width = '';
$v_html_temp_label = '';
$v_column = 0;
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'col';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
while ($table_struct_rec) { 
	$table_struct_row = $table_struct_rec->getRow();
	$v_label = $table_struct_row["label"];
	$v_width = $table_struct_row["width"];
	$v_html_temp_width = $v_html_temp_width  . '<col width="'.$v_width .'">';
	$v_html_temp_label = $v_html_temp_label . '<td align="center">'.$v_label.'</td>';
	$table_struct_rec = $table_struct_rax->readRecord();
	$v_column ++;
}
$v_html_string = $v_html_string  . $v_html_temp_width;
$v_html_string = $v_html_string  . '<tr class="header">';
$v_html_string = $v_html_string  . $v_html_temp_label;
$v_html_string = $v_html_string  . '</tr></table>';
//$v_html_string = $v_html_string  . '<div style="overflow: auto; width: 100%; height:'._CONST_HEIGHT_OF_LIST.';padding-left:0px;margin:0px">';
$v_html_string = $v_html_string  . '<table class="list_table2" width="100%" cellpadding="0" cellspacing="0">';
$v_html_string = $v_html_string  . $v_html_temp_width;
$v_inc = 0;
if ($v_count >0){
	for($row_index = 0;$row_index< $v_count ;$row_index++){
		$v_url = "";
		$v_received_record_xml_data = $arr_all_record[$row_index]['C_RECEIVED_RECORD_XML_DATA'];
		$v_recordset = $arr_all_record[$row_index];
		if (!is_data_valid($v_recordset,$v_report_xml_string,$v_xml_str)){
			continue;
		}
		if ($v_current_style_name == "odd_row"){
			$v_current_style_name = "round_row";
		}else{
			$v_current_style_name = "odd_row";
		}
		$v_html_string = $v_html_string  .'<tr class="'.$v_current_style_name.'" >'; 
		$table_struct_rax = new RAX(); 
		$table_struct_rec = new RAX(); 
		$table_struct_rax->open($v_report_xml_string);
		$table_struct_rax->record_delim = 'col';
		$table_struct_rax->parse();
		$table_struct_rec = $table_struct_rax->readRecord();
		$v_inc ++; 
		while ($table_struct_rec) { 
			$table_struct_row = $table_struct_rec->getRow();
			$v_type = $table_struct_row["type"];
			$v_width = $table_struct_row["width"];
			$v_align = $table_struct_row["align"];
			$v_xml_data = $table_struct_row["xml_data"];
			$v_column_name = $table_struct_row["column_name"];
			$v_xml_tag_in_db = $table_struct_row["xml_tag_in_db"];
			if ($v_xml_data=="true"){
				$column_rax = new RAX(); 
				$column_rec = new RAX();
				$column_rax->open($v_received_record_xml_data);
				$column_rax->record_delim = 'data_list';
				$column_rax->parse();
				$column_rec = $column_rax->readRecord(); 
				$column_row = $column_rec->getRow();
				$v_value = _restore_XML_bad_char($column_row[$v_xml_tag_in_db]);
				$v_html_string = $v_html_string  . '<td align="'.$v_align.'" onclick="'.$v_url.'">'.$v_value.'&nbsp;</td>'; 
			}else{
				$v_value_list = $arr_all_record[$row_index][$v_column_name];
				//if ($v_type=="checkbox"){
				//	$v_url = "row_onclick(" . "document.forms(0).hdn_record_id"  . "," . $v_value_list . "," . "'DISPLAY_SINGLE_RECORD','" . $v_goto_url . "')";
				//}
				$v_html_string = $v_html_string  . Element_Type($v_type); 
			}
			$table_struct_rec = $table_struct_rax->readRecord();
		}
		$v_html_string = $v_html_string  .'</tr>';
	}
}
if ($v_current_style_name == "odd_row"){
	$v_next_style_name = "round_row";
}else{
	$v_next_style_name = "odd_row";
}
$v_html_string = $v_html_string  . _add_empty_row($v_count,_CONST_NUMBER_OF_ROW_PER_LIST,$v_current_style_name,$v_next_style_name,$v_column);
$v_html_string = $v_html_string  .'</table>';
//$v_html_string = $v_html_string  .'</div>';
//lay cac thong tin phan cuoi cua bao cao
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_report_xml_string);
$table_struct_rax->record_delim = 'report_footer';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_report_creator = $table_struct_row["report_creator"];
$v_report_approver = $table_struct_row["report_approver"];
$v_report_signer = $table_struct_row["report_signer"];
$v_html_string = $v_html_string  .'<table width="100%" align="center"><tr><td height="10"></td></tr><tr>';
$v_html_string = $v_html_string  .'<td align="center" class="small_title">'.$v_report_creator.'</td>';
$v_html_string = $v_html_string  .'<td align="center" class="small_title">'.$v_report_approver.'</td>';
$v_html_string = $v_html_string  .'<td align="center" class="small_title">'.$v_report_signer.'</td>';
$v_html_string = $v_html_string  .'</tr></table>';
echo $v_html_string;
//Xuat ra file theo dinh dang html
$v_style_file = "../isa-lib/isa-style/isa_style.css";
$v_str_style = _read_file($v_style_file);
//Tao ra chuoi html
$v_html_content = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>';
$v_html_content = $v_html_content.'<style type=text/css>'.$v_str_style.'</style>';
$v_html_content = $v_html_content.'<body>'.$v_html_string.'</body>';
$v_html_content = $v_html_content.'</html>';
_write_file("test.htm",$v_html_content);
?>
<table width="100%" align="center">
	<tr><td height="10"></td></tr>
	<tr>
		<td align="center" colspan="10">
			<input type="button" value="<?php echo CONST_PRINT_BUTTON; ?>" name="btn_add" class="large_button" onClick="window.print();">
		</td>
	</tr>
</table>
<!--//End//Form-->
</form>
<script language="JavaScript">
	set_focus(document.forms(0));
</script>
